/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha4.entities;

import java.util.ArrayList;
import java.util.Objects;

/**
 *
 * @author Tomique
 */
public class Node {

    private ArrayList<Node> directedNeighbours;
    private ArrayList<Node> neighbours;
    private int id;
    private String authorName;              // jmeno autora, ktery reprezentuje dany uzel
    private float scale;                    // udava nasobek velikost node vzhledem k vychozi hodnote
    private boolean highlighted;            // udava, zda je dany uzel oznaceny
    public Point pos;                       // udava 2D souradnice pozice daneho uzlu
    public Point disp;                      // 2D souradnice pozice pro potreby siloveho algoritmu
    public final float SCALE_MAX = 5.0f;    // maximalni hodnota promenne scale
    public final float SCALE_STEP = 1.08f;  // udava nasobek promenne scale

    private Node() {
        directedNeighbours = new ArrayList<>();
        neighbours = new ArrayList<>();
        scale = 1.0f;
        highlighted = false;
        if (pos == null) {
            pos = new Point();
        }
        disp = new Point();
    }

    public Node(String authorName, int id) {
        this();
        this.authorName = authorName;
        this.id = id;
    }

    public Node(String authorName, int id, int x, int y) {
        this(authorName, id);
        pos = new Point(x, y);
    }

    public Node(String authorName, int id, Point pos) {
        this(authorName, id);
        this.pos = pos;
    }

    // scale
    public float getScale() {
        return scale;
    }

    public void setScale(float scale) {
        this.scale = scale;
    }

    // highlight
    public boolean isHighlighted() {
        return highlighted;
    }

    public void setHighlighted(boolean highlighted) {
        this.highlighted = highlighted;
    }
    // author name

    public String getAuthorName() {
        return authorName;
    }

    // directed neighbours
    public ArrayList<Node> getDirectedNeighbours() {
        return directedNeighbours;
    }

    public int getNoOfDirectedNeighbours() {
        return directedNeighbours.size();
    }

    public void addDirectedNeighbour(Node neighbour) {
        directedNeighbours.add(neighbour);
    }

    // neighbours
    public ArrayList<Node> getNeighbours() {
        return neighbours;
    }

    public int getNoOfNeighbours() {
        return neighbours.size();
    }

    public void addNeighbour(Node neighbour) {
        if (scale < SCALE_MAX) {
            scale *= SCALE_STEP;
        }
        neighbours.add(neighbour);
    }

    // id
    public int getId() {
        return id;
    }

    @Override
    public String toString() {
        // <editor-fold defaultstate="collapsed" desc="toString() implementation">
        StringBuilder sb = new StringBuilder();

        sb.append(authorName).append("\n");

        return sb.toString();
        // </editor-fold>
    }

    @Override
    public boolean equals(Object obj) {
        // <editor-fold defaultstate="collapsed" desc="equals() implementation">
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Node other = (Node) obj;

//        if (!Objects.equals(this.directedNeighbours, other.directedNeighbours)) {
//            return false;
//        }
        if (this.id != other.id) {
            return false;
        }
        if (!Objects.equals(this.authorName, other.authorName)) {
            return false;
        }
        return true;
        // </editor-fold>
    }

    @Override
    public int hashCode() {
        // <editor-fold defaultstate="collapsed" desc="hashCode() implementation">
        int hash = 7;
//        hash = 13 * hash + Objects.hashCode(this.directedNeighbours);
        hash = 13 * hash + this.id;
        hash = 13 * hash + Objects.hashCode(this.authorName);
        return hash;
        // </editor-fold>F
    }
}
